unit GLGUIMouseControl;

interface

uses
  Controls,
  SysUtils,
  Forms,
  Classes,
  Windows,
  GLSCrossXML;

type
  TGLGUICursorRenderType = (crtSystem, crtOpenGL);
  TGLGUICursor = class
  protected
    FRenderType: TGLGUICursorRenderType;
    FImagesSetName: String;
    FCurrentImage: SmallInt;
    FDefaultImage: SmallInt;
    function GetAbsoluteX: Integer;
    function GetAbsoluteY: Integer;
    function GetX: Integer;
    procedure SetX(AValue: Integer);
    function GetY: Integer;
    function GetImage: SmallInt;
    procedure SetImage(AImage: SmallInt);
    function GetImagesSetName(): String;
    procedure SetImagesSetName(AName: String);
    function GetDefaultImage: SmallInt;
    procedure SetDefaultImage(AImage: SmallInt);
  public
    constructor Create();
    property AbsoluteX: Integer read GetAbsoluteX;
    property AbsoluteY: Integer read GetAbsoluteY;
    property X: Integer read GetX write SetX;
    property Y: Integer read GetY;
    property Image: SmallInt read GetImage write SetImage;
    property ImagesSetName: String read GetImagesSetName write SetImagesSetName;
    property DefaultImage: SmallInt read GetDefaultImage write SetDefaultImage;
  end;

  const
    gcrDefault   = TCursor(1);
    gcrNone      = TCursor(2);
    gcrArrow     = TCursor(3);
    gcrCross     = TCursor(4);
    gcrIBeam     = TCursor(5);
    gcrSize      = TCursor(6);
    gcrSizeNESW  = TCursor(7);
    gcrSizeNS    = TCursor(8);
    gcrSizeNWSE  = TCursor(9);
    gcrSizeWE    = TCursor(10);
    gcrUpArrow   = TCursor(11);
    gcrHourGlass = TCursor(12);
    gcrDrag      = TCursor(13);
    gcrNoDrop    = TCursor(14);
    gcrHSplit    = TCursor(15);
    gcrVSplit    = TCursor(16);
    gcrMultiDrag = TCursor(17);
    gcrSQLWait   = TCursor(18);
    gcrNo        = TCursor(19);
    gcrAppStart  = TCursor(20);
    gcrHelp      = TCursor(21);
    gcrHandPoint = TCursor(22);
    gcrSizeAll   = TCursor(23);

function GLGUICursor: TGLGUICursor;

implementation

var
  vGLGUICursor: TGLGUICursor;

function GLGUICursor: TGLGUICursor;
begin
  if (vGLGUICursor = nil) then
    vGLGUICursor := TGLGUICursor.Create;
  Result := vGLGUICursor;
end;

constructor TGLGUICursor.Create();
begin
  FRenderType := crtSystem;
  FDefaultImage := 0;
end;

function TGLGUICursor.GetAbsoluteX: Integer;
begin
  Result := Mouse.CursorPos.X;
end;

function TGLGUICursor.GetAbsoluteY: Integer;
begin
  Result := Mouse.CursorPos.Y;
end;

function TGLGUICursor.GetX: Integer;
begin
  if Assigned(Application.MainForm) then
    Result := Application.MainForm.ScreenToClient(Mouse.CursorPos).X
  else
    Result := 0;
end;

procedure TGLGUICursor.SetX(AValue: Integer);
begin
  SetCursorPos(AValue, AbsoluteY);
end;

function TGLGUICursor.GetY: Integer;
begin
  if Assigned(Application.MainForm) then
    Result := Application.MainForm.ScreenToClient(Mouse.CursorPos).Y
  else
    Result := 0;
end;

function TGLGUICursor.GetImage: SmallInt;
begin
  if FRenderType = crtSystem then
    Result := Screen.Cursor
  else
    Result := FCurrentImage;
end;

procedure TGLGUICursor.SetImage(AImage: SmallInt);
begin
  if FRenderType = crtSystem then
    if Screen.Cursor<>AImage then
      Screen.Cursor := AImage;
end;

function TGLGUICursor.GetImagesSetName(): String;
begin
  Result := FImagesSetName;
end;

procedure TGLGUICursor.SetImagesSetName(AName: String);
begin
end;

function TGLGUICursor.GetDefaultImage: SmallInt;
begin
  Result := FDefaultImage;
end;

procedure TGLGUICursor.SetDefaultImage(AImage: SmallInt);
begin
  FDefaultImage := AImage;
end;

initialization

finalization
  FreeAndNil(vGLGUICursor);

end.
